package com.yd.controller.app;

import java.io.IOException;
import java.net.MalformedURLException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yd.controller.yd.YD_Users;
import com.yd.pojo.Balance;
import com.yd.service.BalanceService;
import com.yd.tool.MD5Hash;
import com.yd.tool.UtsReg;

//she
@Controller
public class BalanceControllerApp {

	@Resource
	private BalanceService balanceService;
	
	//商戶查看自己的餘款
	@RequestMapping("/app/merchant/balance")
	@ResponseBody
	public String app_merchant_balance(HttpServletRequest request) throws MalformedURLException, IOException {
		JSONObject jsonObject = new JSONObject();
		String token="";
		
		if (UtsReg.getStringKB(request.getParameter("token"))) {token = request.getParameter("token").trim();} else {jsonObject.put("msg", "参数 错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		//验证token
		JSONObject yd_users = YD_Users.getUsersByToken(token);
		if (yd_users.getString("error").equals("1")) {jsonObject.put("msg", yd_users.getString("msg"));jsonObject.put("error", "1");return jsonObject.toString();}
		JSONObject users_token = JSONObject.parseObject(yd_users.getString("data"));
		
		EntityWrapper<Balance> ew = new EntityWrapper<Balance>();

		Balance balance = balanceService.selectOne(ew.eq("usersid", users_token.getShort("merchantid")));
        
		jsonObject.put("data", balance);
		jsonObject.put("error", "0");
		jsonObject.put("msg", "成功");

		return jsonObject.toString();
		}
	
	//实际应结款
	
	
	
	
	//已结款




	
}
